$(function(){
	loadMenuTree();
})

function loadMenuTree(){
	layui.use(['tree','util'],function(){
		var layer = layui.layer
			,tree = layui.tree
			,util = layui.util;
		
		$.ajax({
			type : 'get'
			,url : access_url+'/cache/loadcachedata/getmenutreefromcache'
			,dataType:'json'
			,success : function(data){
				if(200!=data.code){
					layer.msg(data.msg, {icon: 5});
				 	return;
				}
				 
				var orgTree = data.retlist;
				 
				tree.render({
					elem: '#menuTree'
				    ,data: orgTree
				    ,id: 'menuTree'
				    ,accordion: true 
				    ,onlyIconControl: true
				    ,click: function(obj){
				    	console.log(obj.data);
				    	console.log(obj.state); //得到当前节点的展开状态：open、close、normal
				    	console.log(obj.elem); 
				    	var data = obj.data;
				    	var menu_id = data.id;
				    	var title = data.title;
				    	var org_type = data.org_type;
				    	parent.$('#parent_id').val(title);
				    	parent.$('#parent_id').attr('data-value',menu_id);
				    	parent.layer.closeAll('iframe');
				    }
				});
			 }
		 })
	})
}